package com.softline.documentsmall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.softline.documentsmall.dao.CollectionMapper;
import com.softline.documentsmall.entity.Collection;
import com.softline.documentsmall.entity.CollectionVO;
import com.softline.documentsmall.entity.ThumbsUp;
import com.softline.documentsmall.service.CollectionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: documentsmall
 * @description:
 * @author: wmj
 * @create: 2020-12-09
 * @ClassName: CollectionServiceImpl
 */
@Service
@Slf4j
public class CollectionServiceImpl extends ServiceImpl<CollectionMapper,Collection> implements CollectionService {

    @Autowired
    CollectionMapper collectionMapper;

    @Override
    public int add(Collection collection) {
        QueryWrapper<Collection> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("passport_id",collection.getPassportId());
        queryWrapper.eq("dictionary_id",collection.getDictionaryId());
        Collection collection1 = this.getOne(queryWrapper);
        int result = 0;
        if(collection1 != null){
            return result;
        }
        return collectionMapper.insert(collection);
    }

    @Override
    public void delete(String passportId, Integer dictionaryId) {
        QueryWrapper<Collection> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("passport_id",passportId);
        queryWrapper.eq("dictionary_id",dictionaryId);
        this.remove(queryWrapper);
    }

    @Override
    public List<CollectionVO> getReconds(String passportId,String type,Integer pageNo, Integer pageSize) {
        return collectionMapper.getReconds(passportId,type,(pageNo-1)*pageSize,pageSize);
    }

    @Override
    public Collection isCollection(String passportId, Integer dictionaryId) {
        QueryWrapper<Collection> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("passport_id",passportId);
        queryWrapper.eq("dictionary_id",dictionaryId);
        Collection collection = this.getOne(queryWrapper);
        return collection;
    }
}
